<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Adjust ODBC settings</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.odbc-rollback.html">« odbc_rollback</a></li>
      <li style="float: right;"><a href="function.odbc-specialcolumns.html">odbc_specialcolumns »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.uodbc.html">ODBC 函数</a></li>
    <li>Adjust ODBC settings</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.odbc-setoption" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">odbc_setoption</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">odbc_setoption</span> &mdash; <span class="dc-title">Adjust ODBC settings</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.odbc-setoption-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>odbc_setoption</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">resource</span> <code class="parameter">$odbc</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$which</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$option</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$value</code></span><br>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   This function allows fiddling with the ODBC options for a
   particular connection or query result.  It was written to help
   find work around to problems in quirky ODBC drivers.  You should
   probably only use this function if you are an ODBC programmer and
   understand the effects the various options will have.  You will
   certainly need a good ODBC reference to explain all the different
   options and values that can be used.  Different driver versions
   support different options.
  </p>
  <p class="para">
   Because the effects may vary depending on the ODBC driver, use of
   this function in scripts to be made publicly available is
   strongly discouraged.  Also, some ODBC options are not available
   to this function because they must be set before the connection
   is established or the query is prepared.  However, if on a
   particular job it can make PHP work so your boss doesn&#039;t tell you
   to use a commercial product, that&#039;s all that really
   matters.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.odbc-setoption-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">odbc</code></dt>

     <dd>

      <p class="para">
       Is a connection id or result id on which to change the settings.
       For SQLSetConnectOption(), this is a connection id.
       For SQLSetStmtOption(), this is a result id.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">which</code></dt>

     <dd>

      <p class="para">
       Is the ODBC function to use. The value should be
       1 for SQLSetConnectOption() and
       2 for SQLSetStmtOption().
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">option</code></dt>

     <dd>

      <p class="para">
       The option to set.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       The value for the given <code class="parameter">option</code>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.odbc-setoption-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.odbc-setoption-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1015">
    <p><strong>示例 #1 <span class="function"><strong>odbc_setoption()</strong></span> examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;1.&nbsp;Option&nbsp;102&nbsp;of&nbsp;SQLSetConnectOption()&nbsp;is&nbsp;SQL_AUTOCOMMIT.<br />//&nbsp;&nbsp;&nbsp;&nbsp;Value&nbsp;1&nbsp;of&nbsp;SQL_AUTOCOMMIT&nbsp;is&nbsp;SQL_AUTOCOMMIT_ON.<br />//&nbsp;&nbsp;&nbsp;&nbsp;This&nbsp;example&nbsp;has&nbsp;the&nbsp;same&nbsp;effect&nbsp;as<br />//&nbsp;&nbsp;&nbsp;&nbsp;odbc_autocommit($conn,&nbsp;true);<br /><br /></span><span style="color: #0000BB">odbc_setoption</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">102</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;2.&nbsp;Option&nbsp;0&nbsp;of&nbsp;SQLSetStmtOption()&nbsp;is&nbsp;SQL_QUERY_TIMEOUT.<br />//&nbsp;&nbsp;&nbsp;&nbsp;This&nbsp;example&nbsp;sets&nbsp;the&nbsp;query&nbsp;to&nbsp;timeout&nbsp;after&nbsp;30&nbsp;seconds.<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">odbc_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">odbc_setoption</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">30</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">odbc_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div></div></div></body></html>